﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		PublicBaseViewData.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion

using System;
using System.Collections.Generic;
using Dexter.Core;
using Dexter.DataTransferObject;
using Dexter.Domain.Model;
using Dexter.Domain.Results;
using Dexter.Services;
using Dexter.Web.Mvc.ViewsData;
using Dexter.Web.Utils;

namespace Dexter.Web.Mvc.ViewModel.ViewsData {
	public class PublicBaseViewData : BaseViewData {
		string copyRight;
		string description;
		string keywords;
		string title;

		public PublicBaseViewData ( IWebUtils webUtils , SiteConfiguration configuration , IUrlBuilder urlBuilder ) : base ( webUtils , configuration , urlBuilder ) {}

		public virtual DexterInfo DexterInfo { get; set; }

		public virtual bool IsFirstTimeUser {
			get { return string.IsNullOrEmpty ( base.WebUtils.GetCookieValue ( "IsFirstTimeUser" ) ); }
		}

		public virtual string Title {
			get {
				if ( string.IsNullOrEmpty ( this.title ) && this.Configuration != null ) {
					return this.Configuration.SeoConfiguration.DefaultTitle;
				}

				return this.title;
			}
			private set { this.title = value; }
		}

		public virtual string Description {
			get {
				if ( string.IsNullOrEmpty ( this.description ) && this.Configuration != null ) {
					return this.Configuration.SeoConfiguration.DefaultDescription;
				}

				return this.description;
			}
			private set { this.description = value; }
		}

		public virtual string KeyWords {
			get {
				if ( string.IsNullOrEmpty ( this.keywords ) && this.Configuration != null ) {
					return string.Join ( "," , this.Configuration.SeoConfiguration.DefaultKeyWords );
				}

				return this.keywords;
			}
			private set { this.keywords = value; }
		}

		public virtual string Author { get; set; }

		public virtual string CopyRight {
			get {
				if ( string.IsNullOrEmpty ( this.copyRight ) && this.Configuration != null ) {
					return this.Configuration.SeoConfiguration.CopyRight;
				}

				return this.copyRight;
			}
			set { this.copyRight = value; }
		}

		public virtual string SearchCriteria { get; set; }

		public virtual IList <CategoryDto> Categories { get; set; }
		public virtual IList<PostDto> RecentPost { get; set; }
		public virtual IList<CommentDto> RecentComment { get; set; }
		public virtual IPagedResult <BlogRoll> BlogsRoll { get; set; }
		public virtual IList<TagDto> TopTags { get; set; }
		public virtual IList<Month> Months { get; set; }
		public virtual IList<PageStructureDto> Pages { get; set; }
		public virtual SearchResult SearchFromReferrer { get; set; }
		public virtual SiteStatistic SiteStatistic { get; set; }

		public virtual void SetTitle ( string pageTitle ) {
			SetTitle ( pageTitle , false );
		}

		public virtual void SetDescription ( string pageDescription ) {
			this.Description = pageDescription.Cut ( 100 );
		}

		public virtual void SetTitle ( string pageTitle , bool removeBaseTitle ) {
			this.Title = removeBaseTitle
			             	? pageTitle
			             	: string.Format ( "{0} - {1}" , this.Configuration.SeoConfiguration.TitlePrefix , pageTitle );
		}

		public virtual void SetMetaKeywords ( string[] values ) {
			if ( values == null || values.Length < 1 ) {
				return;
			}

			this.KeyWords = string.Join ( "," , values );
		}
	}
}
